<style lang="less">
@import './login.less';
</style>


<template>
  <div class="login">

    <div class="login-con">
      <el-card icon="log-in" title="欢迎登录" :bordered="false">
        <div align="center" class="login-title">
          <span>代码生成工具</span>
        </div>
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
<!--          <p class="login-tip">输入任意用户名和密码即可</p>-->
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import LoginForm from '../components/login-form'
import store from "../store";
export default {
  components: {
    LoginForm
  },
  methods: {
    handleSubmit ({ userName, password }) {
      let loginParams = {}
      // 使用账户密码登录
      loginParams.username = userName
      loginParams.password = password
      // loginParams.captcha = that.inputCodeContent
      // loginParams.checkKey = that.currdatetime
      this.$store.dispatch("user/login", loginParams).then((res) => {
        this.$store.dispatch("user/getUserInfo", store.state.user).then((res) => {
          this.$router.push({ name: "Dashboard" })
          this.$notify.success( `欢迎回来`);
        }).catch((err) => {
          this.requestFailed(err);
        });
      })
    } ,
    requestFailed (err) {
      this.$notify[ 'error' ]({
        message: '登录失败',
        description: ((err.response || {}).data || {}).message || err.message || '请求出现错误，请稍后再试',
        duration: 4
      })
    }
  }
}
</script>
